package TransportesMarroquin;

import com.mysql.jdbc.Connection;

import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.sound.sampled.AudioSystem;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JOptionPane;


public class Inicio extends javax.swing.JFrame  {

javax.sound.sampled.Clip sonido;
static String tipousuario;
    boolean verifica =false;
    boolean internet = true;
    boolean activacion = false;
    boolean entrar = false;
      File file;
      ButtonGroup bc;
      String eleccion;
      static String usuario;
      String cor,con,nomb,clave=new String();
      String ecla;
    
      Random rnd = new Random();
      int r;
      String cl []={
          "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
          "P","Q","R","S","T","U","V","W","X","Y","Z",
          "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o",
          "p","q","r","s","t","u","v","w","x","y","z",
          "1","2","3","4","5","6","7","8","9","0"
          
      };
         
      

 
    public Inicio() {
        initComponents();
        bc=new ButtonGroup();
        bc.add(piloto);
        bc.add(administrador);
        bc.add(contador);
        
       
    }

   
  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        cajacon = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cusu = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        ccon = new javax.swing.JPasswordField();
        jButton2 = new javax.swing.JButton();
        ccor = new javax.swing.JTextField();
        cnom = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cape = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        contador = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        piloto = new javax.swing.JRadioButton();
        administrador = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setIconImages(null);
        setResizable(false);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));

        cajacon.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cajaconKeyPressed(evt);
            }
        });

        jButton1.setBackground(new java.awt.Color(153, 0, 0));
        jButton1.setText("Entrar");
        jButton1.setBorderPainted(false);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Contraseña");

        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Usuario");

        cusu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cusuActionPerformed(evt);
            }
        });
        cusu.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cusuKeyReleased(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Marlboro", 0, 48));
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("Marroquin");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cusu, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cajacon, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 52, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel13))
                            .addGap(9, 9, 9)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cusu, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cajacon, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1)
                            .addGap(10, 10, 10))))
                .addContainerGap())
        );

        jLabel10.setText("Usuario");

        jLabel9.setText("electrónico");

        jButton2.setText("Registrarse");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        cnom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cnomActionPerformed(evt);
            }
        });

        jLabel8.setText("Correo ");

        cape.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                capeActionPerformed(evt);
            }
        });

        jLabel6.setText("Nombre");

        jLabel11.setText("Contraseña");

        jLabel7.setText("Apellidos");

        jLabel12.setText("Tipo de ");

        contador.setText("Contador");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel5.setText("Nuevo Usuario");

        piloto.setText("Mantenimiento");

        administrador.setText("Administrador");

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Marroq.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 160, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel6)
                        .addGap(13, 13, 13)
                        .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(cape, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jLabel8))
                            .addComponent(jLabel9))
                        .addGap(14, 14, 14)
                        .addComponent(ccor, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(14, 14, 14)
                        .addComponent(ccon, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel12))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel10)
                        .addGap(24, 24, 24)
                        .addComponent(piloto)
                        .addGap(25, 25, 25)
                        .addComponent(administrador)
                        .addGap(18, 18, 18)
                        .addComponent(contador))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(jButton2)))
                .addGap(119, 119, 119))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(21, 21, 21))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel6))
                            .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel7))
                            .addComponent(cape, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(6, 6, 6)
                                .addComponent(jLabel9))
                            .addComponent(ccor, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel11))
                            .addComponent(ccon, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(piloto)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(administrador)
                                .addComponent(contador)))
                        .addGap(27, 27, 27)
                        .addComponent(jButton2)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
    
    }//GEN-LAST:event_formMouseMoved

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
     
    }//GEN-LAST:event_formMouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try {
            ccor.setBackground(Color.GRAY);
            cnom.setBackground(Color.GRAY);
            cape.setBackground(Color.GRAY);
            ccon.setBackground(Color.GRAY);
            
            if(verifica==false){
                Insertar();
                EliminacionParcial();
            }
            
            if (verifica==true){
                Clave();
                Activacion();
            }
            
            if (activacion == true) {
               
                clave = new String();
                Insertar();
                ccor.setText("");
                cnom.setText("");
                cape.setText("");
                ccon.setText("");
            }
            
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Inicio.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void cnomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cnomActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cnomActionPerformed

    private void capeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_capeActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_capeActionPerformed

    private void cajaconKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cajaconKeyPressed
        if( entrar== true){
            Entrar();
        }
    }//GEN-LAST:event_cajaconKeyPressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
 // Cargo mi Backup
       /* Runtime r=Runtime.getRuntime();
        Process p=null;
        try
        {
            p=r.exec("cmd /c mysql --password=  --user=root practicasp8 < backup.sql");
           // JOptionPane.showMessageDialog(this, "Back Up Cargado");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(this, e); 
        }
      // luego abro 
     dispose();
        Index va = new Index(nomb);
        va.setVisible(true);
        va.setExtendedState(6);
        
       */
       
   if( cajacon.getText().equals(con)){
         
        dispose();
          
     Index va = new Index (nomb);
     va.setVisible(true);
     va.setExtendedState(6);
     
    }
     
        
        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cusuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cusuActionPerformed
        
}//GEN-LAST:event_cusuActionPerformed

    private void cusuKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cusuKeyReleased
        entrar = true;
    }//GEN-LAST:event_cusuKeyReleased
      public void Insertar() throws FileNotFoundException{
     try {
            int resultado = 0 ;
// codio para conectarme 
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
             // coneccion
            Connection conexion;
            conexion = (Connection) dataSource.getConnection();
            PreparedStatement ps = null;
            ps = (PreparedStatement) conexion.prepareStatement("insert into usuario (usuario,nombre,apellido,contrasena,tipousuario) values (?,?,?,?,?)");
     //Id_Usuario
            try{
                if( ccor.getText() == null ? "" == null : ccor.getText().equals("")){

                JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Correo");
                ccor.setBackground(Color.red);
                ccor.setText(""+"Error");

                }
                else {
                ps.setString(1,ccor.getText()); // con el ps genero lo qee voy a ingresar
                //lo genero en orden el 1 va a ser el dato uno en este caso seria nombre
                // y como nombre es varchar tonces sera string
           
                 }
         }catch(Exception e){
             JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
               ccor.setBackground(Color.red);
               ccor.setText(""+"Error");
             }
            
            cor=ccor.getText();
     //nombre
            try{
           
                if( cnom.getText() == null ? "" == null : cnom.getText().equals("")){

                JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Nombre");
                cnom.setBackground(Color.red);
                cnom.setText(""+"Error");

            }
                 else {
             ps.setString(2,cnom.getText()); // con el ps genero lo qee voy a ingresar
            //lo genero en orden el 1 va a ser el dato uno en este caso seria nombre
            // y como nombre es varchar tonces sera string
 }
         }catch(Exception e){
             JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
               cnom.setBackground(Color.red);
               cnom.setText(""+"Error");
         }
            //apellido
            try{
                if( cape.getText() == null ? "" == null : cape.getText().equals("")){

                JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Apellido");
                cape.setBackground(Color.red);
                cape.setText(""+"Error");

            }
                else {
             ps.setString(3,cape.getText());
         }
         }catch(Exception e){
             JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
               cape.setBackground(Color.red);
               cape.setText(""+"Error");
         }
    
       // guardo los datos de nombre y apellido para la carta 
            
              nomb=cnom.getText()+"  "+cape.getText();
            
            
            //Contraseña
            try{
                if( ccon.getText() == null ? "" == null : ccon.getText().equals("")){

                JOptionPane.showMessageDialog(this, "Error, no ingreso datos en Apellido");
                ccon.setBackground(Color.red);
                ccon.setText(""+"Error");

            }
                else {
                    
             ps.setString(4,ccon.getText());
         }
         }catch(Exception e){
             JOptionPane.showMessageDialog(this, "Error, Dato no Ingresado");
               ccon.setBackground(Color.red);
               ccon.setText(""+"Error");
         }
            
            con=ccon.getText();
     //Tipousuario
            try{
                  if (piloto.isSelected()){
                          eleccion="Piloto";

                  }
                  else if(administrador.isSelected()){
                      eleccion="Administrador";}
                  else{
                      eleccion="Contador";
                  }
             ps.setString(5,(eleccion));


             }catch(Exception e ){
                 JOptionPane.showMessageDialog(rootPane, "Dato no ingresado  Revisar Manual"+resultado);

             }
            
            resultado = ps.executeUpdate();
            conexion.close(); // cierro la conexion
            
       // sonido
        try
        {
          sonido = null;
          sonido=AudioSystem.getClip();
          sonido.open(AudioSystem.getAudioInputStream(new File(System.getProperty ("user.dir")+"\\src\\SonidosPractica\\Correcto2.wav")));
          sonido.start();
          
          
          if(verifica==false){
             JOptionPane.showMessageDialog(rootPane, "Bienvenido al programa 'Transportes sobre ruedas'\n "
                  + "A continuación se le desplegara un cuadro de ingreso en el cual debera ingresar \n"
                  + "la contraseña de activacion de su cuenta.  Está fue enviada a su correo");
      
          }
          

      
        }catch(Exception e)
          {System.out.println(""+e);} // fin

                 
                   
              
     }catch(SQLException e){

          JOptionPane.showMessageDialog(rootPane,e.getMessage());
         
         
        
       
           } // fin del catch
    }
    public void Entrar(){
    try {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            Connection conexion = (Connection) dataSource.getConnection();
            Statement instruccion;

            instruccion = (Statement) conexion.createStatement();
            
             // query database
        ResultSet resultSet = instruccion.executeQuery( "SELECT * FROM usuario where usuario like '"+cusu.getText()+"'");
        ResultSetMetaData metaData = (ResultSetMetaData) resultSet.getMetaData();
         int numerodecolumnas = metaData.getColumnCount();

       while (resultSet.next()){

        for(int i=1;i<=numerodecolumnas;i++){
             switch(i){
                 // creo este switch par delimitar el nombre de los label ya establecidos :D
                 case 1:
                     usuario=resultSet.getString(i);
                   break;
                 case 2:
                     nomb=resultSet.getString(i);
                   break;
                case 3:
                     nomb+=" "+resultSet.getString(i);
                   break;
                 case 4:
                     con=resultSet.getString(i);
                   break;
                 case 5:
                     tipousuario = resultSet.getString(i);
                   break;

             }

         } // fin del for
       } // fin 
            conexion.close();
            instruccion.close();
            
        } catch (SQLException ex) {
            Logger.getLogger(LlantasFurgon.class.getName()).log(Level.SEVERE, null, ex);
           
 } 
}
   public void EliminacionParcial(){
       try {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            Connection conexion = (Connection) dataSource.getConnection();
            Statement instruccion;

            instruccion = (Statement) conexion.createStatement();
            
               instruccion.executeUpdate("DELETE from usuario where usuario like '"+cor+"'");
               
            
            conexion.close();
            instruccion.close();
            verifica=true;
        } catch (SQLException ex) {
            Logger.getLogger(LlantasFurgon.class.getName()).log(Level.SEVERE, null, ex);
           
 }
 } // fin del metodo
 public void Clave(){
    for(int p=0;p!=8;p++){
        r=rnd.nextInt(60)+1;
        clave+=cl[r];
       
    }
   
 }
 public void Activacion(){
       try {
			//asigno las propiedades del servidor
                        Properties props = new Properties();
			props.setProperty("mail.smtp.host", "smtp.gmail.com");
			props.setProperty("mail.smtp.starttls.enable", "true");
			props.setProperty("mail.smtp.port", "587");
			props.setProperty("mail.smtp.user", "geovaroma@gmail.com");
			props.setProperty("mail.smtp.auth", "true");

                 
			Session session = Session.getDefaultInstance(props);
                        session.setDebug(true);
			// Construimos el mensaje
			MimeMessage message = new MimeMessage(session);
                        //espesificar Direccion de correo de la que se enviara el correo
                        
			message.setFrom(new InternetAddress("geovaroma@gmail.com"));
			//asignar para quien va dirigido
                       
                        message.addRecipient(Message.RecipientType.TO,new InternetAddress(cor));
                        
                       
                         
                        
			//asunto del correo
                         
                        message.setSubject("Bienvenidad a Tranportes sobre Ruedas");
			
                        
                        //cuerpo del correo
                        
                        
                        message.setText(
                                      "<b> Bienvenido a Transporte sobre Ruedas </b>"
                                + "<br>"+nomb+"<br>"
                                + "Sea Bienvenido a el software desarollado especialmente para Transportes Marroquin<br>"
                                + "le queremos recordar que su contraseña es : "+con+"<br>"
                                + "y su usuario es su correo electronico :"+cor+"<br>"
                                + "de ocasionar algun inconveniente como olvido de su contraseña <br>"
                                + "será enviada de nuevo la contraseña a este correo. <br><br>"
                                + "Antes de disfrutar este servicio active su cuenta. <br>"
                                + "CODIGO DE ACTIVACION :<b>"+clave+"</b>","ISO-8859-1","html");

                        // Lo enviamos.
                     
			Transport t = session.getTransport("smtp");                      
			t.connect("geovaroma@gmail.com", "salesianidilvuore");
			t.sendMessage(message, message.getAllRecipients());

			// Cierre.
			t.close();
                        nomb=new String();
                        con=new String();
                        cor=new String();
                       
                    
			}
		catch (Exception e)
		{
                    JOptionPane.showMessageDialog(rootPane, "Error al envio de la clave, posiblemente no tenga internet \n"
                            + "o bien su correo no es un correo válido :");
                     internet = false;
			}
    if(internet == true){
            while(ecla == null ? clave != null : !ecla.equals(clave)){
            ecla=JOptionPane.showInputDialog("Ingrese el Codigo de Activación ") ; 
            activacion = true;
        }
      }
       
        
}
   
   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Inicio().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton administrador;
    private javax.swing.JPasswordField cajacon;
    private javax.swing.JTextField cape;
    private javax.swing.JPasswordField ccon;
    private javax.swing.JTextField ccor;
    private javax.swing.JTextField cnom;
    private javax.swing.JRadioButton contador;
    private javax.swing.JTextField cusu;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton piloto;
    // End of variables declaration//GEN-END:variables
}
